/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sorting2;

/**
 *
 * @author Student
 */
public class Sorting2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //bubble sort
        boolean swapped;
        int arr[] = new int[50000];
        arr = initArray();
        print(arr);
        do {
            swapped = false;
            for (int i = 1; i < arr.length; i++) {
                if (arr[i - 1] > arr[i]) {
                    int placeholder;
                    placeholder = arr[i];
                    arr[i] = arr[i-1];
                    arr[i-1] = placeholder;
                    swapped = true;
                    
                }
            }
        } while (swapped);
print(arr);

    }

    private static void swap(int i, int i0) {
    }

    private static int[] initArray() {
        int arr[] = new int[50000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 100);
        }
        return arr;
    }

    private static void print(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println("");
    }
}
